import axios from 'axios'
export function request(met, str, config = {}) {
  var _config = config
  if(localStorage.getItem('cookie')){
    _config.cookie = localStorage.getItem('cookie')
  }
  const instance = axios.create({
    // baseURL: "https://autumnfish.cn/",
    // baseURL: "http://music.eleuu.com/",
    // baseURL: "http://localhost:3000",
    baseURL: "http://101.132.168.48:3000",
    timeout: 5000,
    method: met
  })

  instance.interceptors.request.use(config => {
    // config.headers.Authorization = window.sessionStorage.getItem('token')
    return config
  }, err => { })

  instance.interceptors.response.use(res => {
    return res.data
  }, err => {
    return Promise.reject(err)
  })
  if (met === 'POST') {
    return instance({ url: str, data: _config })
  } else if (met === 'GET') {
    return instance({ url: str, params: _config })
  } else if (met === 'PUT') {
    return instance({ url: str, data:_config })
  } else if (met === 'DELETE'){
    return instance({ url: str, params:_config })
  }else {
    this.$message.error('请求类型错误')
  }

}